<?php

namespace app\admin\model\other;

use think\Model;


class Mailbox extends Model
{

    

    

    // 表名
    protected $name = 'mailbox';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'identity_type_text',
        'propose_type_text',
        'is_anonymity_text',
        'status_text',
        'reply_time_text'
    ];
    

    
    public function getTypeList()
    {
        return ['chief' => __('Type chief'), 'lnspection' => __('Type lnspection'), 'unit' => __('Type unit'), 'activity' => __('Type activity')];
    }

    public function getIdentityTypeList()
    {
        return ['10' => __('Identity_type 10'), '20' => __('Identity_type 20')];
    }

    public function getProposeTypeList()
    {
        return ['10' => __('Propose_type 10'), '20' => __('Propose_type 20'), '30' => __('Propose_type 30'), '40' => __('Propose_type 40'), '50' => __('Propose_type 50'), '60' => __('Propose_type 60')];
    }

    public function getIsAnonymityList()
    {
        return ['10' => __('Is_anonymity 10'), '20' => __('Is_anonymity 20')];
    }

    public function getStatusList()
    {
        return ['10' => __('Status 10'), '20' => __('Status 20')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['type'] ?? '');
        $list = $this->getTypeList();
        return $list[$value] ?? '';
    }


    public function getIdentityTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['identity_type'] ?? '');
        $list = $this->getIdentityTypeList();
        return $list[$value] ?? '';
    }


    public function getProposeTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['propose_type'] ?? '');
        $list = $this->getProposeTypeList();
        return $list[$value] ?? '';
    }


    public function getIsAnonymityTextAttr($value, $data)
    {
        $value = $value ?: ($data['is_anonymity'] ?? '');
        $list = $this->getIsAnonymityList();
        return $list[$value] ?? '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }


    public function getReplyTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['reply_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setReplyTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
